package the_Crash.Stylists;

import java.awt.Color;
import java.io.IOException;
import java.util.Date;
import java.util.Random;
import repast.simphony.visualizationOGL2D.DefaultStyleOGL2D;
import saf.v3d.scene.VImage2D;
import saf.v3d.scene.VSpatial;
import the_Crash.Car;
import the_Crash.Direction;

public class CarStylist extends DefaultStyleOGL2D {

	private static Random rnd = new Random(new Date().getTime());
	
	@Override
	public VSpatial getVSpatial(Object agent, VSpatial spatial) {
		if (spatial == null) {
			VImage2D carImg = null;
			try {
				int a = rnd.nextInt(8);				
				String imgFile = "icons/car" + a +  ".png";
				carImg = shapeFactory.createImage(imgFile);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			spatial = carImg;
		}
		return spatial;
	}

	@Override
	public float getScale(Object object) {
		return (float) 0.7;
	}

	@Override
	public Color getColor(Object agent) {
		return Color.red;
	}
	
	@Override
	public float getRotation(Object agent) {
		Car car = (Car) agent;
		Direction currentDirection = car.getCurrentHeading();
		float rotation = 0;
		if (currentDirection == Direction.North) {
			rotation = 90;
		}
		if (currentDirection == Direction.South) {
			rotation = 270;
		}
		if (currentDirection == Direction.East) {
			rotation = 180;
		}
		return rotation;
	}
	
	

}